package com.jinghua.treatment.wechat.controller;

import com.jinghua.treatment.common.GlobalConstant;
import com.jinghua.treatment.common.controller.BaseController;
import com.jinghua.treatment.common.domain.JSONResult;
import com.jinghua.treatment.common.exception.BizException;
import com.jinghua.treatment.entity.SysImMessages;
import com.jinghua.treatment.service.IMMessageService;
import com.jinghua.treatment.tools.QiNiuUtil;
import com.jinghua.treatment.wechat.biz.SMSBiz;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

/**
 * 专门处理聊天信息
 */
@Controller
@RequestMapping("/im")
public class IMController extends BaseController{


    @ApiOperation(value="加载我的聊天记录")
    @RequestMapping(value="/loadMyMessages")
    @ResponseBody
    public JSONResult loadMyMessages(String  whos,Integer fromId, Integer toId) {
        if(StringUtils.isEmpty(whos)||StringUtils.isEmpty(fromId)||StringUtils.isEmpty(toId))
            throw new BizException("参数缺失");
        imMessageService.loadMyMessages(whos,fromId,toId,pager);
        return jsonResult(GlobalConstant.SUCCESS_CODE, "ok", pager);
    }

    @ApiOperation(value="聊天图片的发送")
    @RequestMapping(value="/uploadChatImg")
    @ResponseBody
    public JSONResult uploadChatImg(MultipartFile img,String bizType) {
        QiNiuUtil qiNiuUtil  = new QiNiuUtil("chatimg");
        String fileName ="";
        try {
            fileName =  qiNiuUtil.upload2QiNiu(img.getBytes(),img.getName());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return jsonResult(GlobalConstant.SUCCESS_CODE, "ok", fileName);
    }


    @Resource
    private IMMessageService imMessageService;

}
